package com.naico.core.pojo;

import java.io.Serializable;
import java.util.List;

/**
 * User: Dawood Ajaz
 * Date: Jan 10, 2009
 * Time: 2:32:23 AM
 */
public class ActualPaymentPlan implements PaymentPlan, Serializable {
    private static final long serialVersionUID = 1L;
    private double totalDebtAmount;
    private double totalInterest;
    private double totalMonthlyPayment;
    private List<PaymentSchedule> paymentSchedules;

    public double getTotalDebtAmount() {
        return totalDebtAmount;
    }

    public void setTotalDebtAmount(double totalDebtAmount) {
        this.totalDebtAmount = totalDebtAmount;
    }

    public double getTotalInterest() {
        return totalInterest;
    }

    public void setTotalInterest(double totalInterest) {
        this.totalInterest = totalInterest;
    }

    public double getTotalMonthlyPayment() {
        return totalMonthlyPayment;
    }

    public void setTotalMonthlyPayment(double totalMonthlyPayment) {
        this.totalMonthlyPayment = totalMonthlyPayment;
    }

    public List<PaymentSchedule> getPaymentSchedules() {
        return paymentSchedules;
    }

    public void setPaymentSchedules(List<PaymentSchedule> paymentSchedules) {
        this.paymentSchedules = paymentSchedules;
    }

    public void add(PaymentSchedule paymentSchedule) {
        this.paymentSchedules.add(paymentSchedule);
    }

    public double getTotalPayment() {
        if (this.paymentSchedules == null || this.paymentSchedules.size() == 0)
            return 0.0;

        double totalPayment = 0.0d;
        for (PaymentSchedule schedule : this.paymentSchedules) {
            for (PaymentScheduleItem item : schedule.getPaymentScheduleItems()) {
                totalPayment += item.getPayment();
            }
        }
        return totalPayment;
    }

    public int getTotalMonthsToPayOff() {
        if (this.paymentSchedules == null || this.paymentSchedules.size() == 0)
            return 0;

        int totalMonths = 0;
        for (PaymentSchedule schedule : this.paymentSchedules) {
            int additionalMonths = schedule.getPaymentScheduleItems().size() - totalMonths;
            if (additionalMonths > 0)
                totalMonths += additionalMonths;
        }

        return totalMonths;
    }
}